package gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 * @file CarPurchase.java
 * @version 0.1
 * @author James Dibble 10009689
 */
@Entity
@Table(name = "car_purchase", catalog = "dms", schema = "")
@NamedQueries({
    @NamedQuery(name = "CarPurchase.findAll", query = "SELECT c FROM CarPurchase c"),
    @NamedQuery(name = "CarPurchase.findById", query = "SELECT c FROM CarPurchase c WHERE c.id = :id"),
    @NamedQuery(name = "CarPurchase.findByCar", query = "SELECT c FROM CarPurchase c WHERE c.car = :car"),
    @NamedQuery(name = "CarPurchase.findByDatePurchased", query = "SELECT c FROM CarPurchase c WHERE c.datePurchased = :datePurchased"),
    @NamedQuery(name = "CarPurchase.findByPricePaid", query = "SELECT c FROM CarPurchase c WHERE c.pricePaid = :pricePaid"),
    @NamedQuery(name = "CarPurchase.findByCarReg", query = "SELECT c FROM CarPurchase c WHERE c.carReg = :carReg"),
    @NamedQuery(name = "CarPurchase.findByVin", query = "SELECT c FROM CarPurchase c WHERE c.vin = :vin")})
public class CarPurchase implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "car")
    private int car;
    @Basic(optional = false)
    @Column(name = "date_purchased")
    @Temporal(TemporalType.DATE)
    private Date datePurchased;
    @Basic(optional = false)
    @Column(name = "price_paid")
    private long pricePaid;
    @Basic(optional = false)
    @Column(name = "car_reg")
    private String carReg;
    @Basic(optional = false)
    @Column(name = "vin")
    private String vin;
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public CarPurchase() {
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    // </editor-fold>

    public CarPurchase(Integer id) {
        this.id = id;
    }

    public CarPurchase(Integer id, int car, Date datePurchased, long pricePaid, String carReg, String vin) {
        this.id = id;
        this.car = car;
        this.datePurchased = datePurchased;
        this.pricePaid = pricePaid;
        this.carReg = carReg;
        this.vin = vin;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public int getCar() {
        return car;
    }

    public void setCar(int car) {
        int oldCar = this.car;
        this.car = car;
        changeSupport.firePropertyChange("car", oldCar, car);
    }

    public Date getDatePurchased() {
        return datePurchased;
    }

    public void setDatePurchased(Date datePurchased) {
        Date oldDatePurchased = this.datePurchased;
        this.datePurchased = datePurchased;
        changeSupport.firePropertyChange("datePurchased", oldDatePurchased, datePurchased);
    }

    public long getPricePaid() {
        return pricePaid;
    }

    public void setPricePaid(long pricePaid) {
        long oldPricePaid = this.pricePaid;
        this.pricePaid = pricePaid;
        changeSupport.firePropertyChange("pricePaid", oldPricePaid, pricePaid);
    }

    public String getCarReg() {
        return carReg;
    }

    public void setCarReg(String carReg) {
        String oldCarReg = this.carReg;
        this.carReg = carReg;
        changeSupport.firePropertyChange("carReg", oldCarReg, carReg);
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        String oldVin = this.vin;
        this.vin = vin;
        changeSupport.firePropertyChange("vin", oldVin, vin);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CarPurchase)) {
            return false;
        }
        CarPurchase other = (CarPurchase) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gui.CarPurchase[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
